<template  > 
	 <mdp-table v-if="columnCfgs.length>0" :defaultCheckColumnNum="100" ref="dataSetDataListRef" currOpType="select" operWidth="200" :params="params"  :columnCfgs="columnCfgs" :crudApis="{list:listByDataSetId}" />
</template>

<script>
import * as DataSetApi from '@/api/mdp/dm/dataSet';  
import {listByDataSetId} from '@/api/mdp/dm/data' 
import { mapState } from 'pinia'
import { useUserStore } from '@/store/modules/user'  

export default {
    name:'IndexDataList', 
    components: { 
    },
    computed: { 
        ...mapState(useUserStore,['userInfo']),
        
		idTitleLinksMap(){
			var map=new Map();
			if(!this.editForm.idTitleLinks){
				return map;
			}
			var links=JSON.parse(this.editForm.idTitleLinks)
			links.forEach(k=>{
				map.set(k.id,k.title)
			})
			return map
		}
    },
    props:{
        subOpType:{
            type:String,
            default:'edit'
        }
    },
    watch: {
        $route(to){
            this.initCurrData();
        }, 
    },
    data() {
        return {
            
            editForm: {
                id:'',dsSql:'',dataSource:'',dataModel:'',title:'',cuserid:'',cbranchId:'',ctime:'',euserid:'',etime:'',idTitleLinks:''
            },
             
            load:{query:false},
            columnCfgs:[],
            params:{dataSetId:''}

        }
    },
    methods: {
        listByDataSetId,
        initCurrData(){
            var id=this.$route.params.id
            this.load.query=true 
            this.params.dataSetId=id
            DataSetApi.queryDataSetById({id:id}).then(res=>{
                let {tips,data,fields} = res
                if(tips.isOk){
                    this.editForm=data
                    this.columnCfgs=fields.map(f=>{
                        var col={label:f.remarks||f.columnName,property:this.$mdp.toCamel(f.columnName),colType:f.dataType}
						var title=this.idTitleLinksMap.get(col.property)
						if(title){
							col.label=title
						}
						return col;
                    })
                }else{
                    this.$message({message:tips.msg,type:'error'})
                }
            })
        }
    },
    mounted() { 
        this.initCurrData();
    }
}

</script>

<style scoped>

</style>